import java.io.*;
import java.net.*;
import java.util.BitSet;
import trigest.trigest;

public class TestingSearch{

	public static void main(String argv[]) throws Exception
	{

		String Hash="";
		int pointers[];
		BitSet bit,bit1,bitoriginal,bitm;
		byte[] signature=new byte[1024];
		trigest mike,mike2;
		byte[] signature2=new byte[1024];


		mike=new trigest("I am a chicken that has a lot to eat but cant find anything of that sort. Really doesnt matter");
		mike2=new trigest("chicken");
		

		signature=mike.getSignature();
		signature2=mike2.getSignature();

		
		bit1=fromByteArray(signature2);
		Hash=bit1.toString();
		
		pointers=new int [8192];
		for(int i=0;i<8192;i++)
		{
			pointers[i]=0;
		}
		
		pointers=fromString(Hash);
		
		bit1=BitSetFromIntArray(pointers);
		bit=fromByteArray(signature);
		bitoriginal=bit1;
		bit1.and(bit);
		if(bit1.cardinality()==bitoriginal.cardinality())
		{
			System.out.println("Match");
		}
		
		System.out.println("Values of the Bitset:");
		System.out.println(bit);
		System.out.println(bitoriginal.toString());
		
		
}

	
private static BitSet fromByteArray(byte[] bytes) {
	    BitSet bits = new BitSet();
	    for (int i=0; i<bytes.length*8; i++) {
	        if ((bytes[bytes.length-i/8-1]&(1<<(i%8))) > 0) {
	            bits.set(i);
	        }
	    }
	    return bits;
}


private static int[] fromString(String value) {

    int pointers[],counter=0;
    int pointer=0;
    
    pointers=new int [8192];
	for(int i=0;i<8192;i++)
	{
		pointers[i]=0;
	}
	
    value=value.substring(1);
    counter++;
    while(value.contains(", "))
    {
    pointer=value.indexOf(',');
	pointers[counter]=Integer.parseInt(value.substring(0, pointer));
	value=value.substring(pointer+2);
	counter++;
    }
    
    pointer=value.indexOf('}');
	pointers[counter]=Integer.parseInt(value.substring(0, pointer));
	pointers[0]=counter;
	
	
    return pointers;
}


private static BitSet BitSetFromIntArray(int[] value) {

    BitSet bits = new BitSet();
    
    for(int i=1;i<=value[0];i++)
    {
    	bits.set(value[i]);
    }
    	
    	
    return bits;
}

}